from datetime import datetime
from typing import Literal

from pydantic import BaseModel
from sqlalchemy import Column, Integer, String, DateTime
from sqlalchemy.orm import declarative_base

from utils.enums import Language, PageTypeStatus

Base = declarative_base()


class PageModel(BaseModel):
    page: str
    type: PageTypeStatus
    content: str
    create_time: datetime
    update_time: datetime


class Page(Base):
    __tablename__ = "page"

    id = Column(Integer, primary_key=True, autoincrement=True)
    page = Column(String(255))
    type = Column(String(255))
    content = Column(String)
    content_en = Column(String)
    create_time = Column(DateTime, default=datetime.now())
    update_time = Column(DateTime, default=datetime.now(), onupdate=datetime.now())

    def model(self, language: Language):
        return PageModel(
            page=self.page,  # type: ignore
            type=self.type,  # type: ignore
            content=self.content if Language.CN == language else self.content_en,  # type: ignore
            create_time=self.create_time,  # type: ignore
            update_time=self.update_time,  # type: ignore
        )
